/**
 * tigerrad
 * fall 2006
 */

#ifndef _EXCEPTION_H
#define _EXCEPTION_H

#include <string>

#define EXCEPTION(e) Exception e( __FILE__, __LINE__)

/**
 * A class that signifies an exception.  Use instead of throwing other objects, like
 * strings.
 * Use the macro EXCEPTION(e) to create an Exception instance on the heap named e 
 * with the proper file name and line number.
 */
class Exception 
{
	public:
		/**
		 * Constructor.  Will create a default message.
		 * @param file File exception occured in
		 * @param line Source code line number 
		 */
		Exception(const std::string& file, int line) : _file(file), _line(line), _msg("")
		{
			char lineStr[10];
			sprintf(lineStr, "%d", _line);
			_msg = "Exception at ";
			_msg += _file;
			_msg += ":";
			_msg += lineStr;
			_msg += "\n\t";
		}

		/**
		 * Append a message to this exception.
		 */
		void append(const std::string& msg)
		{
			_msg += msg;
		}

		/**
		 * Return the message associated with the Exception.
		 */
		std::string getMessage() const { return _msg; }

	private:
		std::string _file;
		int _line;
		std::string _msg;
};

#endif // _EXCEPTION_H

